<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'资源添加', styles:'bootstrap,font-awesome,animate,style,dtvalidate,layer,chosen'}){%>
    <style type="text/css">
        body{padding-top:10px;}
    </style>
    <%}%>
</head>
<body>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="col-sm-offset-1 col-sm-10" style="margin-left: -10px;width: 100%;">
                <button type="button" class="return-btn btn btn-w-m btn-primary">返回</button>
                <div style="border-color: #e7eaec;border-image: none;border-style: solid solid none;border-width: 4px 0px;padding-bottom: 15px;margin-top: 10px;" ></div>
            </div>
        </div>
    </div>
</div>
<!-- START 内容部分 -->
<div class="container" >
    <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">
        <input type="hidden" name="id" value="${freight.id}">
        <div class="form-group">
            <label class="control-label col-sm-2">柜型</label>
            <div class="col-sm-6">
                <select id="freightCabinetId" disabled name="freightCabinetId" class="form-control">
                    <option value="">请选择</option>
                    <%for(var dict in cabinet){%>
                    <option value="${dict.id}" <%if(dict.id == freight.freightCabinetId){print("selected");}%> >${dict.cabinetName}</option>
                    <%}%>
                </select>
                <input type="hidden" id="freightCabinetName" name="freightCabinetName">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">运输方式</label>
            <div class="col-sm-6">
                <select  id="freightTransId" disabled name="freightTransId" class="form-control">
                    <option value="">请选择</option>
                    <%for(var dict in transport){%>
                    <option value="${dict.id}"  <%if(dict.id == freight.freightTransId){print("selected");}%> >${dict.transportName}</option>
                    <%}%>
                </select>
                <input type="hidden" id="freightTrans" name="freightTrans">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-1 col-sm-offset-1">仓库:</label>
            <div class="col-sm-2">
                <select  id="fromPortId" disabled name="fromPortId" class="form-control">
                    <option value="">请选择</option>
                    <%for(var dict in port){%>
                    <option value="${dict.id}"<%if(dict.id == freight.fromPortId){print("selected");}%> >${dict.portName}</option>
                    <%}%>
                </select>
                <input type="hidden" name="fromPortName" id="fromPortName">
            </div>
            <div class="col-sm-2">
                <select  id="toPortId" disabled name="toPortId" class="form-control">
                    <option value="">请选择</option>
                    <%for(var dict in port){%>
                    <option value="${dict.id}" <%if(dict.id == freight.toPortId){print("selected");}%> >${dict.portName}</option>
                    <%}%>
                </select>
                <input type="hidden" name="toPortName" id="toPortName">
            </div>.
            <div class="col-sm-2">
                <select  id="toWareId" disabled name="toWareId" class="form-control">
                    <option value="">${freight.toWareName}</option>
                </select>
                <input type="hidden" name="toWareName" id="toWareName">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label text-right">运费</label>
            <div class="col-sm-6">
                <input type="text" id="freightTotal" value="${freight.freightTotal}"  name="freightTotal" onkeyup="value=value.replace(/[^\d\.]/g,'')" class="form-control"/>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">分摊方式</label>
            <div class="col-sm-6">
                <select  id="freightType" name="freightType" class="form-control">
                    <option value="">请选择</option>
                    <option value="重量" <%if(freight.freightType == "重量"){print("selected");}%>>重量</option>
                    <option value="体积" <%if(freight.freightType == "体积"){print("selected");}%>>体积</option>
                    <option value="整柜" <%if(freight.freightType == "整柜"){print("selected");}%>>整柜</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" class="save-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
                <button type="button" class="return-btn btn btn-warning">
                    <i class="fa fa-save"></i> 返回
                </button>
            </div>
        </div>
    </form>
</div>
<!-- END 内容部分 -->

<!-- START 公共脚本 -->
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,dtvalidate,dtvalidate-lang-zh_cn,laydate,layer,chosen,chosen-demo'}){}%>
<!-- END 公共脚本 -->
<script>
    var cvalidator;
    $(function(){

        //初始化验证器
        cvalidator = $.fn.dlshouwen.validator.init($('#info-form'));

        //提交表单
        $('.save-btn').on('click',function(){

            //数据提交
            $.post('/sea/physical/freight/usave.do',$('#info-form').serialize(),function(data){
                if( data.ok ){
                    parent.layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']}, function(){
                        parent.$freightTable.bootstrapTable('refresh');
                        parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
                    });
                }else{
                    parent.layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                }
            });
        });
        //返回
        $('.return-btn').on('click',function(){
            parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
        });
    });

    $("#toPortId").change(function () {
        var parentId=$("#toPortId").val();
        getCategory(parentId);
    });

    function getCategory(parentId) {
        $.ajax({
            url:'/sea/physical/port/findByParenId',
            data:{
                id:parentId
            },
            type:'post',
            success:function (data) {
                var list=data;
                $("#toWareId").html('');
                if(list.length>0){
                    var category='<option value="">全部分类</option>';
                    for(var i=0;i<list.length;i++){
                        category+='<option value="'+list[i].id+'">'+list[i].portName+'</option>';
                    }
                    $("#toWareId").html(category);
                }
            }
        });
    }
</script>
</body>
</html>